<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - Apr 13, 2013
 */
/**
 * 
 * @param string $whereCol Selects from projects which get a column from database.
 * @param numeric $whereID Selects from projects which get project ID from database.
 * @param string $db Database connecting string.
 * @return string It returns customerinfo, cusname and cus_id from project table in a variable as $CI.
 */
function getProjectsA($whereCol, $whereID, $db) {
    $query = "SELECT * FROM projects WHERE $whereCol = '".$whereID."'";
        try {
            $stmt = $db->prepare($query);
            $stmt->execute();
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }
        $rows = $stmt->fetchAll();

        foreach($rows as $row1) {
            $CI.="<option value='{$row1["project_id"]}'>";
                $CI.=$row1['projectname'];
            $CI.="</option>";
            $CI++;
        }
        return $CI;
}

/**
 * 
 * @param string $whereCol Selects from projects which get a column from database.
 * @param numeric $whereID Selects from projects which get project ID from database.
 * @param string $db Database connecting string.
 * @return string It returns customerinfo, cusname and cus_id from project table in a variable as $CI. Here customer info is concated with project id.
 */
function getProjects($whereCol, $whereID, $db) {
    $query = "SELECT * FROM projects WHERE $whereCol = '".$whereID."'";
        try {
            $stmt = $db->prepare($query);
            $stmt->execute();
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }
        $rows = $stmt->fetchAll();

        foreach($rows as $row1) {
            $CI.="<option value='{$row1["project_id"]}'>";
                $CI.=$row1['projectname'];
                $CI.=" ( ";
                $CI.=getName('customerinfo', 'cusname', 'cus_id', $row1['cus_id'], $db);
                $CI.=" ) ";
            $CI.="</option>";
            $CI++;
        }
        return $CI;
}
?>
